<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 6.1.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/blog/images/logo.svg" color="#222">

<link rel="stylesheet" href="/blog/css/main.css">


<link rel="stylesheet" href="/blog/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"az12348.gitee.io","root":"/blog/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="序言： 一个朝十晚六的工作，记录一个二十岁年轻人上班时异想天开的想法。">
<meta property="og:type" content="article">
<meta property="og:title" content="记录一次上班摸鱼2022-8-12">
<meta property="og:url" content="https://az12348.gitee.io/blog/2022/08/12/%E8%AE%B0%E5%BD%95%E4%B8%80%E6%AC%A1%E4%B8%8A%E7%8F%AD%E6%91%B8%E9%B1%BC2022-8-12/index.html">
<meta property="og:site_name" content="阿宅">
<meta property="og:description" content="序言： 一个朝十晚六的工作，记录一个二十岁年轻人上班时异想天开的想法。">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2022-08-12T06:28:30.000Z">
<meta property="article:modified_time" content="2022-08-12T08:07:30.619Z">
<meta property="article:author" content="阿宅">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://az12348.gitee.io/blog/2022/08/12/%E8%AE%B0%E5%BD%95%E4%B8%80%E6%AC%A1%E4%B8%8A%E7%8F%AD%E6%91%B8%E9%B1%BC2022-8-12/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'en'
  };
</script>

  <title>记录一次上班摸鱼2022-8-12 | 阿宅</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="Toggle navigation bar">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/blog/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">阿宅</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/blog/" rel="section"><i class="fa fa-home fa-fw"></i>Home</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/blog/about/" rel="section"><i class="fa fa-user fa-fw"></i>About</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/blog/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>Archives</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="https://az12348.gitee.io/blog/2022/08/12/%E8%AE%B0%E5%BD%95%E4%B8%80%E6%AC%A1%E4%B8%8A%E7%8F%AD%E6%91%B8%E9%B1%BC2022-8-12/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.gif">
      <meta itemprop="name" content="阿宅">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="阿宅">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          记录一次上班摸鱼2022-8-12
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2022-08-12 14:28:30 / Modified: 16:07:30" itemprop="dateCreated datePublished" datetime="2022-08-12T14:28:30+08:00">2022-08-12</time>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <blockquote>
<p>序言： 一个朝十晚六的工作，记录一个二十岁年轻人上班时异想天开的想法。</p>
</blockquote>
<span id="more"></span>

<p>现在是下午两点半，我感觉自己今天的任务量已经够了，可能在四点左右的生活还会补点代码吧。至少现在我不是很想写了，这几天高强度的编码搞得我人有点麻。原本想刷刷抖音，但因最近博客经常在写所以，又想写写博客，也正好我博客全都是日常生活的琐碎事情，分享一下一些没啥用的技术片段。</p>
<p>想想自己好像工作了这么久都没写点什么，想的乱七八糟的。聊起编程，没接触的人估计大部分会联想到啥啥黑客，花里胡哨五颜六色的代码满屏幕飞，什么乱七八糟的“高科技”界面到处显示。事实上不说全部，可能大部分开发工程师都多少有一点鄙夷。面对这些“高科技”，我个人比较喜欢更朴素一些的搭配，更多趋向于黑色灰字，因为大部分时间都在看屏幕，有时候白色看久了眼镜就花，黑色相对而言我觉得会更加舒适一点。</p>
<blockquote>
<p>Demo</p>
</blockquote>
<p>代码，Js、C、Python、Java、Go、C++语言数不胜数，不过一般常用的就那几个而已。以前在上学的时候看别人写爬虫老炫酷了，哇，这人可以随意的爬别人的数据，好厉害呀 ~ 然后，自己屁颠屁颠的去 B 站学，学了几天，用 Python 写了一个程序，跑了两天宿舍里的 IP 封了一半，然后就基本没在跑过，后面觉得其实拿到这些数据也没什么用，又不能卖 米 ，爬来还浪费时间，就没弄了。后面实习摸鱼没事情做，又写了一个，反正用的也不是我自己电脑，嘿嘿，这里展示一个当时用的简化Java版的方法。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br></pre></td><td class="code"><pre><span class="line">//输入网址 和 正则表达式 解析 网页 的 工具类</span><br><span class="line">public class Requesthtml &#123;</span><br><span class="line">    public Map&lt;String, Object&gt; getHttpJson(String url,String [] parses) throws Exception &#123;</span><br><span class="line">        try &#123;</span><br><span class="line">            URL realUrl = new URL(url);</span><br><span class="line">            HttpURLConnection connection = (HttpURLConnection) realUrl.openConnection();</span><br><span class="line">            connection.setRequestProperty(&quot;accept&quot;, &quot;*/*&quot;);</span><br><span class="line">            connection.setRequestProperty(&quot;connection&quot;, &quot;Keep-Alive&quot;);</span><br><span class="line">            connection.setRequestProperty(&quot;user-agent&quot;, &quot;Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)&quot;);</span><br><span class="line">            // 建立实际的连接</span><br><span class="line">            connection.connect();</span><br><span class="line">            //请求成功</span><br><span class="line">            if (connection.getResponseCode() == 200) &#123;</span><br><span class="line">                InputStream is = connection.getInputStream();</span><br><span class="line">                ByteArrayOutputStream baos = new ByteArrayOutputStream();</span><br><span class="line">                //10MB的缓存</span><br><span class="line">                byte[] buffer = new byte[10485760];</span><br><span class="line">                int len = 0;</span><br><span class="line">                while ((len = is.read(buffer)) != -1) &#123;</span><br><span class="line">                    baos.write(buffer, 0, len);</span><br><span class="line">                &#125;</span><br><span class="line">                String jsonString = baos.toString();</span><br><span class="line">                //查看是否获取到网页数据</span><br><span class="line">//                System.out.println(&quot;jsonString&quot;+jsonString);</span><br><span class="line">                baos.close();</span><br><span class="line">                is.close();</span><br><span class="line">                //开始解析网页</span><br><span class="line">                Map&lt;String, Object&gt; map = new HashMap&lt;&gt;();</span><br><span class="line">                Map&lt;String,Object&gt; data=new HashMap&lt;&gt;();</span><br><span class="line">                data.put(&quot;data&quot;,jsonString);</span><br><span class="line">                for (int pr=0;pr&lt;parses.length;pr++)&#123;</span><br><span class="line">                    List resultList = getContext(data.get(&quot;data&quot;).toString(),parses[pr]);</span><br><span class="line">                    if(parses.length==1)&#123;</span><br><span class="line">                        map.put(&quot;data&quot;,resultList);</span><br><span class="line">                        return map;</span><br><span class="line">                    &#125;else&#123;</span><br><span class="line">                        data.put(&quot;data&quot;,resultList);</span><br><span class="line">                    &#125;</span><br><span class="line">                    if(pr==parses.length-1)&#123;</span><br><span class="line">                        map.put(&quot;data&quot;,resultList);</span><br><span class="line">                        return map;</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">                //转换成json数据处理</span><br><span class="line">                // getHttpJson函数的后面的参数1，表示返回的是json数据，2表示http接口的数据在一个（）中的数据</span><br><span class="line">                return map;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125; catch (MalformedURLException e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125; catch (IOException ex) &#123;</span><br><span class="line">            ex.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">        return null;</span><br><span class="line">    &#125;</span><br><span class="line">    public static List getContext(String html, String matching) &#123;</span><br><span class="line">        List resultList = new ArrayList();</span><br><span class="line">        String rule = matching;</span><br><span class="line">        Pattern p = Pattern.compile(rule);</span><br><span class="line">        Matcher m = p.matcher(html);//开始编译</span><br><span class="line">        while (m.find()) &#123;</span><br><span class="line">            int i = 1;</span><br><span class="line">            resultList.add(m.group(i));//获取被匹配的部分</span><br><span class="line">            i++;</span><br><span class="line">        &#125;</span><br><span class="line">        return resultList;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>方法解释</p>
</blockquote>
<p>没有包装请求头，也没有 IP 池、线程池，需要自己配，方法两个参数：网址和String 类型的数组，首先向对应网址建立连接，这里就要开始用 请求头与 IP 了，建立请求之后就会返回数据。是不是很容易？其实不然，返回的数据都是 由 HTML 组成的页面静态代码，这里就讲到我们的第二个参数，这里用数组完全是因为我懒，方法判断数组长度进行循环，而数组中的正则表达式也必须要是层级关系，就像你剥洋葱一样，我们爬数据也是需要一层一层的剔出多余没用的垃圾信息，表达式数组也是一样，会轮询按表达式一次一次的剔除，最后返回给你。很简单的方法，我觉得功能很简单就没用那些爬虫框架，反正也就写着玩玩，代码可以直接拿，写的很简陋，大佬看看就好。</p>
<blockquote>
<p>继续唠嗑</p>
</blockquote>
<p>以前在电影里看到的 JC 叔叔，那些犯罪分子打个电话就能查到他在哪。表面波澜无惊，心里：我操，牛逼！ 然后又屁颠屁颠的去网上找资料，打电话可能有点难，容易暴露自己，但能不能做一个网页，这个网页可以藏在小程序，你的小说广告，你的点开的任何一个网页，它只要一点击这个网页我就能锁定到它的位置呢？嗯，答案是可以的，可以通过请求 IP 定位到用户大概位置，可能可以定位到跟精细的位置，这个我没有更加深入探索（狗头保命），但是定位到市级别城市是肯定随随便便的，至于能不能定到你家小区，这个有待考证，但是一般来说你点了也无所谓，因为人家通过这个 IP 获得了地址又怎么样，它又不知道你是谁又不知道你住那个房（狗头）。都是些没用的技术，其实如果真的是认识的人想找你还用的着这种技术？不认识你的人找到也没有意义，就像我之前说的《垃圾数据》。更多的时候想的是一些，给我自己的生活写一个软件以便利我的生活，要不就是，搞钱 | 搞钱 | 搞钱，每天上班的生活也甚是枯燥。</p>
<p>好啦，码点代码等会就下班了，祝开心 ~ </p>
<img src=https://az12348.gitee.io/img/blog/blog_image_004.jpg width=70% />

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">没想到竟是月亮也会有彩虹相伴。</span><br></pre></td></tr></table></figure>

    </div>

    
    
    

      <footer class="post-footer">

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/blog/2022/08/09/%E6%80%BB%E7%BB%93%E6%88%91%E7%9A%84%E7%BC%BA%E9%99%B7%E4%BB%A5%E5%8F%8A%E6%94%B9%E5%96%84%E6%96%B9%E6%B3%95/" rel="prev" title="总结我的缺陷以及改善方法">
      <i class="fa fa-chevron-left"></i> 总结我的缺陷以及改善方法
    </a></div>
      <div class="post-nav-item">
    <a href="/blog/2022/08/29/%E7%AD%89%E5%BE%85%E3%80%81%E8%AE%A1%E5%88%92%E4%B8%8E%E5%BF%83%E6%80%81/" rel="next" title="等待、计划与心态">
      等待、计划与心态 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          Table of Contents
        </li>
        <li class="sidebar-nav-overview">
          Overview
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">阿宅</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/blog/archives/">
        
          <span class="site-state-item-count">12</span>
          <span class="site-state-item-name">posts</span>
        </a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">阿宅</span>
</div>

        








      </div>
    </footer>
  </div>

  
  <script src="/blog/lib/anime.min.js"></script>
  <script src="/blog/lib/velocity/velocity.min.js"></script>
  <script src="/blog/lib/velocity/velocity.ui.min.js"></script>

<script src="/blog/js/utils.js"></script>

<script src="/blog/js/motion.js"></script>


<script src="/blog/js/schemes/muse.js"></script>


<script src="/blog/js/next-boot.js"></script>




  















  

  

</body>
</html>
